
public class IfStmt {
	String IF ;
	String lp;
	Expression exp;
	String rp;
	Statement st;
	IfStmt2 IF2;
	int lineNum;
	int charPos;
	
	public IfStmt(String IF, String lp, Expression exp, String rp, Statement st, IfStmt2 IF2, int line, int charP){
		this.IF = IF;
		this.lp = lp;
		this.exp = exp;
		this.rp = rp;
		this.st = st;
		this.IF2 = IF2;
		this.lineNum = line;
		this.charPos = charP;
	}
	public String toString(){
		String ret = "IfStmt\n";
		String s = "";
		if (exp != null) {
			s +=  exp.toString();
		}

		if (st != null) {
			s +=  st.toString();
		}
		if (IF2 != null) {
			s +=  IF2.toString();
		}
		for(String st: s.split("\n")){
			if(st!= "")
				ret += "| " + st + "\n";
		}
		return ret;
	}
	public void check() throws SemanticException {
		SymbolTable table = SymbolTable.getInstance();
		if(exp !=null){
			exp.fromIf = true;
			exp.check(null);
		}
		if (st != null) {
			table.incrementNumOfIfs();
			table.toggleInIf();
			st.check();
			table.toggleInIf();
		}
		if (IF2 != null) {
			table.numberOfElses++;
			// table.incrementNumOfIfs();
			table.toggleInElse();
			// table.toggleInIf();
			IF2.check();
			// table.toggleInIf();
			table.toggleInElse();
		}
	}
}
